#include "Exception.h"

using namespace Woo;
using namespace IO;

Exception::Exception() :
	m_ErrorMessage("Throw a exception."),
	m_SourceInfo("No source information.")
{
	StackTrace();
}

Exception::Exception(string msg) :
	m_ErrorMessage(msg),
	m_SourceInfo("No source information.")
{
	StackTrace();
}

Exception::Exception(string msg, string file, unsigned int line) :
	m_ErrorMessage(msg)
{
	char buffer[512];
	memset(buffer, 0, 512);
	sprintf(buffer, "[File]: %s [Line]: %d", file.c_str(), line);

	m_SourceInfo.append(buffer);

	StackTrace();
}

Exception::~Exception()
{
}

void Exception::StackTrace()
{
	UInt32 uEBP;
	__asm__ (
		"movl %%ebp, %0" 
		: "=r"(uEBP) );

	while(true)
	{
		if(uEBP == 0)
			break;
		char buffer[64];
		memset(buffer, 0, 64);
		sprintf(buffer, "0x%08X\r\n", *((UInt32*)uEBP + 1));
		m_StackTraceInfo.append(buffer);
		uEBP = *((UInt32*)uEBP);
	}
}

string Exception::GetSource()
{
	return m_SourceInfo;
}

string Exception::GetStackInfo()
{
	return m_StackTraceInfo;
}

string Exception::GetMessage()
{
	return m_ErrorMessage;
}

void Exception::SetMessage(string msg)
{
	m_ErrorMessage = msg;
}

NotImplementedException::NotImplementedException()
{
}

NotImplementedException::NotImplementedException(string msg) :
	Exception(msg)
{
}

NotImplementedException::NotImplementedException(string msg, string file, unsigned int line) :
	Exception(msg, file, line)
{
}

NotImplementedException::~NotImplementedException()
{
}

IOException::IOException()
{
}

IOException::IOException(string msg) :
	Exception(msg)
{
}

IOException::IOException(string msg, string file, unsigned int line) :
	Exception(msg, file, line)
{
}

IOException::~IOException()
{
}

NotSupportedException::NotSupportedException()
{
}

NotSupportedException::NotSupportedException(string msg) :
	Exception(msg)
{
}

NotSupportedException::NotSupportedException(string msg, string file, unsigned int line) :
	Exception(msg, file, line)
{
}

NotSupportedException::~NotSupportedException()
{
}

StreamException::StreamException()
{
}

StreamException::StreamException(string msg) :
	IOException(msg)
{
}

StreamException::StreamException(string msg, string file, unsigned int line) :
	IOException(msg, file, line)
{
}

StreamException::~StreamException()
{
}

StreamOpenException::StreamOpenException()
{
}

StreamOpenException::StreamOpenException(string msg) :
	StreamException(msg)
{
}

StreamOpenException::StreamOpenException(string msg, string file, unsigned int line) :
	StreamException(msg, file, line)
{
}

StreamOpenException::~StreamOpenException()
{
}

StreamReadException::StreamReadException()
{
}

StreamReadException::StreamReadException(string msg) :
	StreamException(msg)
{
}

StreamReadException::StreamReadException(string msg, string file, unsigned int line) :
	StreamException(msg, file, line)
{
}

StreamReadException::~StreamReadException()
{
}

StreamWriteException::StreamWriteException()
{
}

StreamWriteException::StreamWriteException(string msg) :
	StreamException(msg)
{
}

StreamWriteException::StreamWriteException(string msg, string file, unsigned int line) :
	StreamException(msg, file, line)
{
}

StreamWriteException::~StreamWriteException()
{
}

StreamClosedException::StreamClosedException()
{
}

StreamClosedException::StreamClosedException(string msg) :
	StreamException(msg)
{
}

StreamClosedException::StreamClosedException(string msg, string file, unsigned int line) :
	StreamException(msg, file, line)
{
}

StreamClosedException::~StreamClosedException()
{
}

ArgumentException::ArgumentException()
{
}

ArgumentException::ArgumentException(string msg) :
	Exception(msg)
{
}

ArgumentException::ArgumentException(string msg, string file, unsigned int line) :
	Exception(msg, file, line)
{
}

ArgumentException::~ArgumentException()
{
}

ArgumentNullException::ArgumentNullException()
{
}

ArgumentNullException::ArgumentNullException(string msg) :
	ArgumentException(msg)
{
}

ArgumentNullException::ArgumentNullException(string msg, string file, unsigned int line) :
	ArgumentException(msg, file, line)
{
}

ArgumentNullException::~ArgumentNullException()
{
}

IndexOutOfRangeException::IndexOutOfRangeException()
{
}

IndexOutOfRangeException::IndexOutOfRangeException(string msg) :
	Exception(msg)
{
}

IndexOutOfRangeException::IndexOutOfRangeException(string msg, string file, unsigned int line) :
	Exception(msg, file, line)
{
}

IndexOutOfRangeException::~IndexOutOfRangeException()
{
}

FileNotFoundException::FileNotFoundException()
{
}

FileNotFoundException::FileNotFoundException(string msg) :
	IOException(msg)
{
}

FileNotFoundException::FileNotFoundException(string msg, string file, unsigned int line) :
	IOException(msg, file, line)
{
}

FileNotFoundException::~FileNotFoundException()
{
}

DirectoryNotFoundException::DirectoryNotFoundException()
{
}

DirectoryNotFoundException::DirectoryNotFoundException(string msg) :
	IOException(msg)
{
}

DirectoryNotFoundException::DirectoryNotFoundException(string msg, string file, unsigned int line) :
	IOException(msg, file, line)
{
}

DirectoryNotFoundException::~DirectoryNotFoundException()
{
}

